<template>
  <div class="" v-if="visible">
    <div class="followInfo">
      <div class="followInfobox">
        <div class="followInfo_title">预约单取消</div>
        <div class="task_detail">
          <div class="task_detail_header">
            <div class="task_detail_headerbox">
              <div class="title">{{ dataSource.carNo ? dataSource.carNo : '-' }}</div>
              <div class="name">
                <div class="txt">{{ dataSource.customerName ? dataSource.customerName : '-' }}</div>
              </div>
              <img @click="handleTel(dataSource.mobile1)" class="tel_icon" src="@/assets/images/tel_icon.png" />
            </div>
          </div>
        </div>
      </div>

      <div class="followInfo_content">
        <SelectTime
          class="followInfo_item"
          :label="'取消时间'"
          :field="'cancelDate'"
          :type="'date'"
          :requireFlag="true"
          @getFieldVal="getFieldVal"
        ></SelectTime>

        <SelectTime
          class="followInfo_item"
          :label="'下次预约日期'"
          :field="'nextBookingDate'"
          :type="'date'"
          :requireFlag="true"
          @getFieldVal="getFieldVal"
        ></SelectTime>


        <SelectInput
          class="followInfo_item"
          :label="'备注'"
          :field="'bookingCancel'"
          :requireFlag="true"
          @getFieldVal="getFieldVal"
        ></SelectInput>


      </div>
      <div class="fixCenter_btn">
        <div class="cancel_btn" @click="closePop">取消</div>
        <div class="confirm_btn" @click="formOnSubmit">确认</div>
      </div>



    </div>
    <div class="mask" @click.stop="closePop"></div>
  </div>
</template>

<script>
import { DatetimePicker, Field, Form, Tab, Tabs, Toast } from 'vant'
import { getCookies, isPhone } from '@/utils/util.js'
import SelectRadio from './SelectRadio'
import SelectTime from './SelectTime'
import SelectInput from './SelectInput'
import repairApi from '@/api/repairApi'

export default {
  name: 'FollowEdit',
  components: {
    Field,
    Form,
    DatetimePicker,
    Tab,
    Tabs,
    Toast,
    SelectRadio,
    SelectTime,
    SelectInput,
  },
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    billId: {
      type: String,
      default: null,
    },
    dataSource: {
      type: Object,
      default: {},
    },
  },
  data() {
    return {
      showTimerPicker: false,

      formData: {
        billId: '', //单据ID
        cancelDate: '', //取消日期
        nextBookingDate: '', //下次预约日期
        bookingCancel: '', //取消原因
      },
      columns: [],
      detailId: '',
      userId: getCookies('userId'), //用户ID，必填，String
      userInfo: getCookies('userInfo'),
    }
  },

  mounted() {

  },
  // watch: {
  //   visible: {
  //     handler: function (val, oldVal) {
  //       if (val) {
  //       }
  //     },
  //     deep: true,
  //     immediate: false,
  //   },
  // },
  methods: {

    getFieldVal(field, value) {
      this.formData[field] = value
    },

    handleTel(tel) {
      if (isPhone()) {
        window.location.href = `tel:${tel}`
      } else {
        Toast('请在手机端使用此功能')
      }
    },

    formOnSubmit() {
      repairApi
            .cancelRepairBooking({
              ...this.formData,
              userId: this.userId,
              billId:this.dataSource.billId
            })
            .then((res) => {
              console.log(res)
              if (res.code != 0) {
                Toast('取消成功')
                this.closePop()
               this.$parent.getDetail(this.dataSource.billId)
              } else {
                Toast( res.msg)
              }
            })
    },


    closePop() {
      this.$emit('close')
    },
  },
}
</script>

<style lang="less" scoped>
body {
  // background: #f3f3f3;
}
.flex {
  display: flex;
  align-items: center;
}
.registerDetail {
  background: #f3f3f3;
  overflow: hidden;
  .detail_header {
    justify-content: space-between;
    margin: 0.2rem 0.2rem;
    border-radius: 5px;
    background: #fff;
    padding: 0.3rem;
    .detail_header_lt {
      .carNo {
        font-size: 0.32rem;
        font-weight: bold;
        margin-bottom: 0.2rem;
        .carStatus {
          border: 1px solid #35bc04;
          color: #35bc04;
          border-radius: 5px;
          padding: 0.1rem 0.1rem;
          font-size: 0.24rem;
          text-align: center;
          margin-left: 0.1rem;
        }
      }
      .hank {
        font-size: 0.28rem;
        color: #666;
        .name {
          border-right: 2px solid #ccc;
          padding-right: 0.1rem;
          margin-right: 0.1rem;
        }
      }
    }
    .detail_header_rt {
      justify-content: flex-start;
      .txt {
        font-size: 0.28rem;
        color: #161616;
      }
      .icon-tel {
        color: #fff;
        background: #35bc04;
        font-size: 0.32rem;
        padding: 0.1rem;
        border-radius: 50%;
        margin-right: 0.1rem;
      }
    }
  }
  .formData {
    background: #fff;
    overflow: hidden;
  }
}

.submitBtn {
  background: #409eff;
  color: #fff;
  width: 75%;
  margin: auto;
  text-align: center;
  padding: 0.25rem;
  border-radius: 5px;
  margin-top: 0.6rem;
  font-size: 0.3rem;
  margin-bottom: 0.5rem;
}
.voicebox {
  position: relative;
  .icon-voice {
    position: absolute;
    bottom: 10px;
    right: 10px;
    font-size: 20px;
    color: #409eff;
  }
}
.task_detail {
  // margin-top: 50px;
  .task_detail_header {
    padding: 17px 0 10px;
    background: #fff;
    // margin-bottom: 10px;
    border-bottom: 1px solid #f1f1f1;
    position: relative;

    .title {
      text-align: center;
      //font-family: Alibaba;
      font-weight: 700;
      font-size: 16px;
      color: #333333;
      max-width: 70%;
      text-overflow: ellipsis;
      white-space: nowrap;
      overflow: hidden;
      margin: auto;
    }
    .name {
      display: flex;
      text-align: center;
      width: 100%;
      justify-content: center;
      margin-top: 10px;

      .txt {
        //font-family: Alibaba;
        font-weight: 400;
        font-size: 12px;
        color: #999999;
        text-align: center;
        margin-right: 10px;
      }
    }
    .tel_icon {
      position: absolute;
      top: 16px;
      right: 10px;
      width: 29px;
    }
  }
  .follow_result {
    display: flex;
    padding: 10px;
    // border-bottom: 6px solid #f7f7f7;
    border-bottom: 1px solid #f7f7f7;

    .itembox {
      font-weight: 400;
      font-size: 12px;
      color: #4e5969;
      border-radius: 32px 32px 32px 32px;
      background: #f7f7f7;
      padding: 8px 10px;
      margin-right: 10px;
      &.active {
        color: #165dff;
        background: #d8e3ff;
        border-radius: 32px 32px 32px 32px;
      }
    }
  }

  .tabbox {
    // padding: 0 10px;
    padding-top: 15px;
    border-top: 1px solid #f7f5f5;
    margin-top: 15px;
    position: relative;
    width: 7.5rem;
    overflow: hidden;
    .tab_list {
      width: 10rem;
      overflow-x: auto;
      clear: both;
      .tab_item {
        font-weight: 400;
        font-size: 14px;
        color: #4e5969;
        text-align: center;
        background: #f7f7f7;
        border-radius: 32px;
        padding: 8px 16px;
        margin-right: 6px;
        cursor: pointer;
        float: left;
        &:last-child {
          margin-right: 0;
        }
        &.active {
          color: #165dff;
          text-align: center;
          background: #d8e3ff;
        }
      }
    }
  }
}

.followInfo {
  position: fixed;
  width: 100%;
  height: calc(100vh - 116px);
  overflow: auto;
  bottom: 0;
  left: 0;
  z-index: 102;
  box-shadow: 0px 1px 0px 0px rgba(40, 47, 56, 0.04);
  border-radius: 10px 10px 0px 0px;
  background: #fff;
  &::-webkit-scrollbar {
    display: none;
  }
  .followInfobox {
    border-radius: 10px 10px 0px 0px;
    position: fixed;
    top: 116px;
    left: 0;
    width: 100%;
    background: #fff;
  }
  .followInfo_title {
    text-align: center;
    padding: 10px;
    border-bottom: 1px solid #f2f2f2;
    font-weight: 600;
    font-size: 17px;
    color: #1d2129;
  }

  .followInfo_content {
    padding: 10px;
    border-top: 6px solid #f7f7f7;
    margin-bottom: 60px;
    margin-top: 102px;
    .followInfo_item {
      margin-bottom: 10px;
    }

    .followInfo_name {
      margin-bottom: 10px;
      .name {
        width: 100px;
        padding: 5px 8px;
        font-weight: 700;
        font-size: 10px;
        color: #165dff;
        background: #e8f5ff;
        border-radius: 2px 2px 2px 2px;
      }
    }
  }
}
.mask {
  position: fixed;
  width: 100%;
  height: 100vh;
  bottom: 0;
  left: 0;
  z-index: 101;
  background: rgba(0, 0, 0, 0.5);
}
.radiobox {
  box-shadow: 0px 5px 5px 0px rgba(0, 0, 0, 0.02);
  border-radius: 4px 4px 4px 4px;
  border: 1px solid #f4f4f6;
  padding: 8px 17px 20px 17px;
  .card_label {
    display: flex;
    margin-bottom: 10px;
    .require_icon {
      font-weight: 400;
      font-size: 12px;
      color: #ff4848;
    }
    .label_txt {
      font-weight: 400;
      font-size: 12px;
      display: flex;
      color: #86909c;
    }
  }
  .card_select {
    display: flex;
    flex-wrap: wrap;
    .radio_item {
      width: 33%;
      display: flex;
      align-items: center;
      .item_icon {
        width: 18px;
        display: block;
        margin-right: 10px;
      }
      .item_name {
        font-weight: 600;
        font-size: 12px;
        color: #2f2f2f;
      }
    }
    .select_time {
      width: 100%;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .time_val {
        font-weight: 700;
        font-size: 12px;
        color: #2f2f2f;
      }
      .icon-right {
        font-size: 16px;
        color: #c9cdd4;
      }
    }
  }
}
.fixCenter_btn {
  display: flex;
  width: 100%;
  box-sizing: border-box;
  position: fixed;
  bottom: 0;
  left: 0;
  background: #fff;
  .cancel_btn {
    width: 50%;
    font-weight: 400;
    font-size: 18px;
    color: #1d2129;
    border-right: 1px solid #e5e6eb;
    padding: 12px;
    text-align: center;
  }
  .confirm_btn {
    font-weight: 400;
    width: 50%;
    font-size: 18px;
    color: #165dff;
    padding: 12px;
    text-align: center;
  }
}
</style>
